/*
** counter.c for counter in /home/comet_a//afs/local/sys_unix/my_select/counter
** 
** Made by alexandre comet
** Login   <comet_a@epitech.net>
** 
** Started on  Fri Jan 13 22:03:42 2012 alexandre comet
** Last update Mon Nov 19 12:02:14 2012 thomas nadalie
*/

#include	<unistd.h>
#include	<curses.h>
#include	<term.h>
#include	<stdlib.h>

int		my_putchar(int c)
{
  write(1, &c, 1);
  return (0);
}

int		my_putnbr(int nb)
{
  if (nb < 0)
    {
      my_putchar('-');
      nb = nb * -1;
    }
  if (nb > 9)
    my_putnbr(nb / 10);
  my_putchar((nb % 10) + 48);
  return (0);
}

int		clear_s()
{
  if (tgetent(0, "xterm") != 1)
    {
      write(2, "No such entry or terminfo database coud not be found\n", 47);
      return (0);
    }
  tputs(tgetstr("cl", 0), 1, my_putchar);
  return (0);

}

int		my_gt()
{
  if (tgetent(0, "xterm") != 1)
    {
      write(2, "No such entry or terminfo database coud not be found\n", 47);
      return (0);
    }
  //tgoto(tgetstr("cm", NULL), 0, 0);
  tputs(tgoto(tgetstr("cm", NULL), 0,0), 1, my_putchar);
}

int		main()
{
  int		r;

  r = 1;
  clear_s();
  while (1)
    {
      sleep(1);
      my_putnbr(r);
      my_gt();
      r++;
    }
  return (0);
}
